package com.dong.ui.util;

import com.dong.common.constant.PropertiesConst;
import com.dong.common.util.PropertiesUtils;
import com.dong.ui.constant.IconConst;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;

/**
 * @description: 图片工具类
 * @author: 陈瑞东
 * @create: 2021-08-31 14:15
 */
public class ImageUtils {

    /**
     * 设置ImageIcon大小
     * @param imageIcon
     * @param width
     * @param height
     * @return
     */
    public static ImageIcon scaleImage(ImageIcon imageIcon, int width, int height) {
        if (imageIcon.getImageLoadStatus() == MediaTracker.ERRORED) {
            imageIcon = IconUtils.getStatusIcon(PropertiesConst.ICON_KEY_404);
        }
        Image image = imageIcon.getImage().getScaledInstance(width, height, Image.SCALE_DEFAULT);
        return new ImageIcon(image);
    }
}
